package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
/**
 * 项目搭建试验用类，和项目业务无关
 * Created by tanjun on 2021-11-30.
 */
@Controller
public class HelloController {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/")
    @ResponseBody
    public String getHello() {
        return "hello";
    }

    @RequestMapping("/person")
    @ResponseBody
    public String person(){
        return "person";
    }

    @RequestMapping("/mybatis")
    @ResponseBody
    public String mybatis(HttpServletRequest request) {
        String name=request.getParameter("name");
        User user=new User();
        user.setUserid(null);//自增
        user.setName(name);
        user.setLoginid(name);
        //数据库保存加密后密码
        user.setPassword(passwordEncoder.encode(name));
        user.setPasswordfaultnum(0);
        user.setDirectorgid(0);
        user.setIslock("0");
        user.setCreateuser(0);
        user.setDestory("0");
        user.setEffective("1");
        user.setCreatetime(new Date());
        userMapper.insert(user);
        return "success";
    }

}
